/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[GenericsMethod2.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package generics;

/**
 * 泛型方法
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class GenericsMethod2 {

	/**
	 * 获得数组中的最大值和最小值
	 * 
	 * @param arrays
	 * @return 最大值和最小值组成的Pair对象
	 */
	public static Pair<String> minmax(String[] arrays) {
		if (arrays == null || arrays.length == 0) {
			return null;
		}

		String min = arrays[0];
		String max = arrays[0];
		for (int i = 0; i < arrays.length; i++) {
			if (min.compareTo(arrays[i]) > 0) {
				min = arrays[i];
			}
			if (max.compareTo(arrays[i]) < 0) {
				max = arrays[i];
			}
		}
		return new Pair<String>(min, max);
	}

	public static void main(String[] args) {
		String[] arrays = { "D", "A", "C", "B", "E" };
		Pair<String> p = minmax(arrays);
		System.out.println(p);
	}
}
